<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <AssemblyName>SuperFileCheck</AssemblyName>
    <OutputType>Exe</OutputType>
    <TargetFramework>$(NetCoreAppToolCurrent)</TargetFramework>
    <PlatformTarget>AnyCPU</PlatformTarget>
    <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
    <AppendTargetFrameworkToOutputPath Condition="'$(BuildingInsideVisualStudio)' == 'true'">true</AppendTargetFrameworkToOutputPath>
    <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
    <EnableDefaultEmbeddedResourceItems>false</EnableDefaultEmbeddedResourceItems>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <OutputPath>$(RuntimeBinDir)\SuperFileCheck</OutputPath>
    <RunAnalyzers>false</RunAnalyzers>
  </PropertyGroup>

  <PropertyGroup>
    <!-- Massage the OutputRID into an JITTools package RID that we can download -->
    <_jitToolsRidPlatformIndex>$(OutputRID.LastIndexOf('-'))</_jitToolsRidPlatformIndex>
    <JITToolsRidWithoutPlatform>$(OutputRID.Substring(0, $(_jitToolsRidPlatformIndex)))</JITToolsRidWithoutPlatform>
    <JITToolsRidPlatform>$(OutputRID.Substring($(_jitToolsRidPlatformIndex)).TrimStart('-'))</JITToolsRidPlatform>

    <!-- If it's not win/osx/linux-musl, it's a non-portable Linux. Treat as Linux. -->
    <JITToolsRidWithoutPlatform Condition="'$(JITToolsRidWithoutPlatform)' != 'win' and '$(JITToolsRidWithoutPlatform)' != 'osx' and '$(JITToolsRidWithoutPlatform)' != 'linux-musl'">linux</JITToolsRidWithoutPlatform>

    <!-- There are no x86 packages, so use x64 -->
    <JITToolsRidPlatform Condition="'$(JITToolsRidPlatform)' == 'x86'">x64</JITToolsRidPlatform>
    <JITToolsRidPlatform Condition="'$(JITToolsRidPlatform)' == 'arm' and '$(JITToolsRidWithoutPlatform)' == 'win'">arm64</JITToolsRidPlatform>
    <JITToolsRid Condition="'$(JITToolsRid)' == ''">$(JITToolsRidWithoutPlatform)-$(JITToolsRidPlatform)</JITToolsRid>

    <JITToolsVersion Condition="'$(JITToolsVersion)' == '' and '$(JITToolsRid)' == 'linux-arm64'">$(runtimelinuxarm64MicrosoftNETCoreRuntimeJITToolsVersion)</JITToolsVersion>
    <JITToolsVersion Condition="'$(JITToolsVersion)' == '' and '$(JITToolsRid)' == 'linux-x64'">$(runtimelinuxx64MicrosoftNETCoreRuntimeJITToolsVersion)</JITToolsVersion>
    <JITToolsVersion Condition="'$(JITToolsVersion)' == '' and '$(JITToolsRid)' == 'linux-musl-arm64'">$(runtimelinuxmuslarm64MicrosoftNETCoreRuntimeJITToolsVersion)</JITToolsVersion>
    <JITToolsVersion Condition="'$(JITToolsVersion)' == '' and '$(JITToolsRid)' == 'linux-musl-x64'">$(runtimelinuxmuslx64MicrosoftNETCoreRuntimeJITToolsVersion)</JITToolsVersion>
    <JITToolsVersion Condition="'$(JITToolsVersion)' == '' and '$(JITToolsRid)' == 'win-arm64'">$(runtimewinarm64MicrosoftNETCoreRuntimeJITToolsVersion)</JITToolsVersion>
    <JITToolsVersion Condition="'$(JITToolsVersion)' == '' and '$(JITToolsRid)' == 'win-x64'">$(runtimewinx64MicrosoftNETCoreRuntimeJITToolsVersion)</JITToolsVersion>
    <JITToolsVersion Condition="'$(JITToolsVersion)' == '' and '$(JITToolsRid)' == 'osx-arm64'">$(runtimeosxarm64MicrosoftNETCoreRuntimeJITToolsVersion)</JITToolsVersion>
    <JITToolsVersion Condition="'$(JITToolsVersion)' == '' and '$(JITToolsRid)' == 'osx-x64'">$(runtimeosxx64MicrosoftNETCoreRuntimeJITToolsVersion)</JITToolsVersion>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="$(MicrosoftCodeAnalysisCSharpVersion)" />
    <PackageDownload Condition="'$(DotNetBuildSourceOnly)' != 'true'" Include="runtime.$(JITToolsRid).Microsoft.NETCore.Runtime.JIT.Tools">
      <Version>[$(JITToolsVersion)]</Version>
    </PackageDownload>
  </ItemGroup>

  <Target Name="CopyJitTools" AfterTargets="Build">
    <ItemGroup>
      <JitToolsFiles Include="$(NuGetPackageRoot)\runtime.$(JITToolsRid).microsoft.netcore.runtime.jit.tools\$(JITToolsVersion)\runtimes\**\*.*" />
    </ItemGroup>
    <Copy SourceFiles="@(JitToolsFiles)"
          SkipUnchangedFiles="true"
          OverwriteReadOnlyFiles="true"
          DestinationFolder="$(OutputPath)\runtimes\%(RecursiveDir)" />
  </Target>

</Project>
